package tools;



//import com.xiaoxing.memtools.MemAgent;


public class SizedObjects {
	
	public static class MyClass {
//		long value;
		int value;
//		long a;
//		boolean b1;
//		boolean b2;
//		boolean b3;
//		boolean b4;

//		boolean b5;
//		boolean b6;
//		boolean b7;
//		boolean b8;
//		boolean b9;
//		boolean b10;
//		boolean b11;
//		boolean b12;
//		
//		boolean b13;
	}
	
	public static class MyClass2 extends MyClass {
//		boolean b1;
//		boolean b2;
//		boolean b3;
//		boolean b4;

//		boolean b5;
//		boolean b6;
//		boolean b7;
//		boolean b8;
//		boolean b9;
//		boolean b10;
//		boolean b11;
//		boolean b12;
//		
//		boolean b13;
		
	}
	
	
	

	
	public static int UNIT_SIZE = 8;
	
	public static class Object16 {
		public volatile int value = 0;
	}

	public final static class Object16Hard extends Object16 {
	}

	public final static class Object24Hard extends Object16 {
//		public volatile int value = 0;
		public long p1;
	}
	
	public final static class Object32Hard extends Object16 {
//		public volatile int value = 0;
		public long p1, p2;
	}
	public final static class Object40Hard extends Object16 {
//		public volatile int value = 0;
		public long p1, p2, p3;
	}
	public final static class Object48Hard extends Object16 {
//		public volatile int value = 0;
		public long p1, p2, p3, p4;
	}
	public final static class Object56Hard extends Object16 {
//		public volatile int value = 0;
		public long p1, p2, p3, p4, p5;
	}
	public final static class Object64Hard extends Object16 {
//		public volatile int value = 0;
		public long p1, p2, p3, p4, p5, p6;
	}
	public final static class Object72Hard extends Object16 {
//		public volatile int value = 0;
		public long p1, p2, p3, p4, p5, p6, p7;
	}
	public final static class Object80Hard extends Object16 {
//		public volatile int value = 0;
		public long p1, p2, p3, p4, p5, p6, p7, p8;
	}
	public final static class Object88Hard extends Object16 {
//		public volatile int value = 0;
		public long p1, p2, p3, p4, p5, p6, p7, p8, p9;
	}
	public final static class Object96Hard extends Object16 {
//		public volatile int value = 0;
		public long p1, p2, p3, p4, p5, p6, p7, p8, p9, p10;
	}
	public final static class Object104Hard extends Object16 {
//		public volatile int value = 0;
		public long p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11;
	}
	
	public static class Object24 extends Object16 {
		long placeHolder24;
	}
	
	public static class Object32 extends Object24 {
		long placeHolder32;
	}
	
	public static class Object40 extends Object32 {
		long placeHolder40;
	}
	
	public static class Object48 extends Object40 {
		long placeHolder48;
	}
	
	public static class Object56 extends Object48 {
		long placeHolder56;
	}
	
	public static class Object64 extends Object56 {
		long placeHolder64;
	}
	
	public static class Object72 extends Object64 {
		long placeHolder72;
	}
	
	public static class Object80 extends Object72 {
		long placeHolder80;
	}
	
	public static class Object88 extends Object80 {
		long placeHolder88;
	}

	public static class Object96 extends Object88 {
		long placeHolder96;
	}
	
	public static class Object104 extends Object96 {
		long placeHolder104;
	}

	public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
//		MyClass c = new MyClass();
//		MyClass2 c2 = new MyClass2();
		
//		int a = 0;
		
//		long size = MemoryUtil.memoryUsageOf(c);
		
				
//		long fsize = MemAgent.getObjectSize(c);
//		long ssize = MemAgent.getObjectSize(c2);
		
		
		try {
			for (int i = 16; i <= 104; i += 8) {
				String className = String.format("tools.SizedObjects$Object%dHard", i);
//				String className = "tools.SizedObjects$Object24";
				Class<?> c;
				c = Class.forName(className);
				Object o = c.newInstance();
//				Object16 o16 = (Object16) o;
//				System.out.format("%s: %d\n", className, MemAgent.getObjectSize(o));
			}
			
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		/*
		int len = 10;
		int size = 88;
		String objName = String.format("tools.SizedObjects$Object%d", size);
		Class<?> c = Class.forName(objName);
		
		Object16[] array = (Object16[]) Array.newInstance(c, len);
		System.out.format("%s[%d]: %d.\n", objName, len, MemAgent.getObjectSize(array));
		for (int i = 0; i < array.length; i++) {
			array[i] = (Object16) c.newInstance();
		}
		for (Object16 o : array) {
			System.out.format("Name:%s: Size:%d.\n", o.getClass().getName(), MemAgent.getObjectSize(o));
		}
		*/
		
//		System.out.format("father: %d, son: %d\n", fsize, ssize);

	}

	
}
